const seeFm = require('../../config.js');
import {$await} from '../../utils/util';
import {commonAPI} from '../../api/roomManage/roomManage'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow:"",
    room_number:'',
    cengIsShow:0,
    // 选择关闭原因
    choice1:'0',
    choice2:'0',
    choice3:'0',
    reason:'',
    roomInfo:{},
    is_self:false
  },
  hideCeng:function(){
    this.setData({
      cengIsShow:0,
      choice1:'0',
      choice2:'0',
      choice3:'0',
    })
  },
  changeType:function(e){
    console.log(e.currentTarget.dataset['type'])
    console.log(e.currentTarget.dataset['choice'])
    if(e.currentTarget.dataset['choice'] == 'choice1'){
      this.setData({
        choice1:e.currentTarget.dataset['type'],
        choice2:'0',
        choice3:'0',
        reason:'预约人数过少'
      })
    }else if(e.currentTarget.dataset['choice'] == 'choice2'){
      this.setData({
        choice1:'0',
        choice2:e.currentTarget.dataset['type'],
        choice3:'0',
        reason:'临时有事'
      })
    }else if(e.currentTarget.dataset['choice'] == 'choice3'){
      this.setData({
        choice1:'0',
        choice2:'0',
        choice3:e.currentTarget.dataset['type'],
        reason:'其它原因',
      })
    }
  },
  //开启话题
  async start(e){
    let params = {
      'room_number':this.data.room_number,
    }
    const [err,res] = await $await(commonAPI.start({...params}))
      if(res){
        wx.redirectTo({ 
          url: '/pages/audioRoom/audioRoom?roomNumber='+this.data.room_number+'&from1=wxapp'
        })
      }
  },
  async getDate(){
    let params = {
      'room_number':this.data.room_number,
    }
    const [err,res] = await $await(commonAPI.getData({...params}))
      if(res){
        this.setData({
          roomInfo:res
        })
        if(res.number == wx.getStorageSync('userInfo').user_id){
          this.setData({
            is_self:true
          })
        }
      }
  },
  isEnd(){
    this.setData({
      cengIsShow:1
    })
  },
  async sureEnd(){
    if(this.data.reason==''){
      wx.showToast({
        title: '请选择结束原因',
        icon: 'none',
        duration: 2000,
      })
      return
    }
    let params = {
      'room_number':this.data.room_number,
      'reason':this.data.reason
    }
    const [err,res] = await $await(commonAPI.dissolve({...params}))
      if(res){
        wx.redirectTo({
          url: '/pages/salon/salon'
        })
      }
  },
  edit:function(){
    wx.redirectTo({
      url: '/pages/roomInfo/roomInfo?room_number='+this.data.room_number
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      // options.roomNumber
      room_number:options.roomNumber,
      isshow:options.isShow
    })
    this.getDate();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})